package test;

import com.qf.bean.Teacher;
import com.qf.service.TeacherService;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 2019/11/30
 * Administrator
 * springdata1130
 * 面向对象面向君  不负代码不负卿
 */
public class Demo3 {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext applicationContext =
                new ClassPathXmlApplicationContext("springData.xml");
       TeacherService teacherService=(TeacherService) applicationContext.getBean("teacherServiceImpl");
      //  List<Teacher> teachers = teacherService.findbyids(2,4);
      //  List<Teacher> teachers = teacherService.findByTnameStartingWith("z");
        //List<Teacher> teachers = teacherService.findByTidIn(Arrays.asList(1,3,5));
      //  List<Teacher> teachers = teacherService.findAll(new Sort(Sort.Direction.DESC,"birthday"));
       //多列排序 order by 列名1 desc/asc,列名2  desc/asc
       //注意:只有当列名1的值重复的时候，重复的那部分数据才会按照列名2排序
        //如果出售让你改日期相同，则根据id排序
    /*    ArrayList arrayList = new ArrayList();
        arrayList.add(new Sort.Order(Sort.Direction.ASC,"birthday"));
        arrayList.add(new Sort.Order(Sort.Direction.DESC,"tid"));
        List<Teacher> teachers = teacherService.findAll(new Sort(arrayList));*/

    //页码值从0开始
        Page<Teacher> page = teacherService.findByTidIn(Arrays.asList(1, 2, 3, 4, 5), new PageRequest(0, 2, Sort.Direction.DESC,"tid"));
        List<Teacher> teachers = page.getContent();
        for (Teacher teacher : teachers) {
            System.out.println(teacher);
        }
        System.out.println("总条数:"+page.getTotalElements());
        System.out.println("总页数:"+page.getTotalPages());
        System.out.println("上一页:"+page.previousPageable());
        System.out.println("下一页:"+page.nextPageable().getPageNumber());
        System.out.println("当前页码:"+page.getNumber());
      //  System.out.println(teacherService.countByTnameContaining("z"));
    }
}
